#pragma once
#include <iostream>
#include <string>
#include <fstream>
#include <unordered_map>

using namespace std;
const string filename = "./dict.txt";

static void split(string line, string* key, string* value)
{
    auto s = line.find(":");
    if (s != string::npos)
    {
        *key = line.substr(0, s);
        *value = line.substr(s + 1);
    }
}

class Dict
{
public:
    Dict()
    {
        ifstream dic(filename);
        if (!dic.is_open())
        {
            cout << "file open error" << endl;
            exit(1);
        }
        string line;
        while (getline(dic, line))
        {
            string patr1;
            string part2;
            split(line, &patr1, &part2);
            _dict.insert({patr1, part2});
        }

        dic.close();
    }

    string translate(string word)
    {
        for (auto ch : _dict)
        {
            if (ch.first == word)
            {
                return ch.second;
            }
        }

        return "";
    }
    ~Dict()
    {

    }
private:
    unordered_map<string, string> _dict;
};